function y = clusters(xvals,Z,Tstep)  

rng(1);

plots = 1;
close all;
%y is a function that takes the non-dogmatic weight x, the number of required preferences Z, and the timestep, as input,
%and returns a cell with 2 arguments. The first output argument is the matrix of utility discount factors beta).  
%The second argument is the list of etas.  The weights on clusters are
%contained in the "weight" variable.

load('deltaeta_data.mat');

Ddata = deltaeta_data;

%Ddata = [deltaeta_data(:,1)/100, deltaeta_data(:,2)];

[idx,C] = kmeans(Ddata,Z,'Distance','sqeuclidean','MaxIter',500,'replicates',500);
%,'Start','sample'
N = length(Ddata);
weight = zeros(1,Z);



if plots == 1
    figure;
    
    hold on
end

for i = 1:Z
    weight(i) = sum(idx==i)/N;
    if plots ==1
          plot(Ddata(idx==i,1),Ddata(idx==i,2),'.','MarkerSize',18);
    end
end
if plots ==1
    plot(C(:,1),C(:,2),'kx','MarkerSize',15,'LineWidth',3); 
    xlabel('\delta');
    ylabel('\eta');
    hold off
end

V = [];

for x = xvals
    
    V = [V; 1000*x*ones(1,Z+2)];
    
    beta = (1./(1+0.01*C(:,1))).^(Tstep);

    V = [V; beta, C(:,2)];

end

y = V;
%



